package com.wxpay.client.util;

import java.util.HashMap;
import java.util.Map;

import com.boxin.ims.modules.wechat.utils.XMLUtils;

public class MoneyTest {
	final static  String urlOne = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";//发送红包
	
	final static String  urlTwo = "https://api.mch.weixin.qq.com/mmpaymkttransfers/send_coupon";//发放代金券
	
	final static String urlThree = "https://api.mch.weixin.qq.com/mmpaymkttransfers/query_coupon_stock";//代金券批次信息
	
	final static String urlFour = "https://api.mch.weixin.qq.com/promotion/query_coupon";//代金券信息
	
	final static String urlFive = "https://api.mch.weixin.qq.com/secapi/pay/refund";//微信退款
	
	
	public static void main(String[] args) throws InterruptedException {
		
		//hongbao("o0Tvajqf4BJx5qALEK6Nsw-eDAAo");
		
		//applyRefund();
		
		//daijinquan();
		
		hongbao("o0TvajmYwe-u-Mz-X3lgKAPtFPRc");//马经理
		
		/*
		for(int i = 0; i<20; i++){
			
			
						
						hongbao("o0TvajmYwe-u-Mz-X3lgKAPtFPRc");//马经理
						hongbao("o0TvajmMQx6gyZA_W-E5hyczC7KQ");//小屈
						hongbao("o0TvajkXAPqblDuG96oDyghiYqOE");//小白
						hongbao("o0Tvajpl0jQKcUrIaAw5jm_9uTis");//小霍
						hongbao("o0TvajgyRT9-slOBI2e4xjuS3bP8");//朱姐
						hongbao("o0Tvajv7xLeBBIIy_w3BJrXWY2I4");//贾总
						
						Thread.sleep(5000);
						
			
		}
*/
		
		/*			
		Runnable runner = new Runnable() {
			@Override
			public void run() {
				try {
								Thread.sleep(5000);//一小时后查看是否支付，未支付：作废		
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		};
		new Thread(runner).start();
		//hongbao("");//贾总*/
	}

	
	//发代金券测试
	public static void daijinquan() {
		String opendId = "oitGqjq3szPgwPhM8XqKsnc343";
		String appId = "wx4d624b8f3ac5744f";
		String mchId = "1231888902";
		String partnerkey = "105A59DDCADB4E87AE41309F7ED81570";
		String keystoreFile = "D:/WeChatCert/certificate/cert_user_2.p12";
		
		String orderNNo =  MoneyUtils.getOrderNo(mchId) ; 
		System.out.println(orderNNo);
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("coupon_stock_id", "144262");
		map.put("openid_count", "1");
		map.put("partner_trade_no", orderNNo);
		map.put("openid", opendId);
		map.put("appid", appId);
		map.put("mch_id", mchId);
		map.put("nonce_str", MoneyUtils.buildRandom());
		map.put("sign", MoneyUtils.createSign(map,partnerkey));
		
		String result = "";
		try {
			System.out.println(MoneyUtils.createXML(map));
			result = MoneyUtils.doSendMoney(urlTwo, MoneyUtils.createXML(map),mchId,keystoreFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("result:"+result);
	}

	//发红包测试
	public static void hongbao(String opendId) {
		
		String appId = "wx297a2be207a6e693";
		String mchId = "1240689402";
		String partnerkey = "384ud9fkmyinyue3k39dleis9xmd8ekd";
		String keystoreFile = "D:/WeChatCert/certificate/yinyueguangbo/cert_user_430000084.p12";
		
		String orderNNo =  MoneyUtils.getOrderNo(mchId) ; 
		System.out.println(orderNNo);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("nonce_str", MoneyUtils.buildRandom());//随机字符串
		map.put("mch_billno", orderNNo);//商户订单
		map.put("mch_id", mchId);//商户号
		map.put("wxappid", appId);//商户appid
		map.put("nick_name", "音乐广播");//提供方名称
		map.put("send_name", "音乐广播");//用户名
		map.put("re_openid", opendId);//用户openid
		map.put("total_amount", 100);//付款金额
		map.put("min_value", 100);//最小红包
		map.put("max_value", 100);//最大红包
		map.put("total_num", 1);//红包发送总人数
		map.put("wishing", "音乐广播祝您万事如意");//红包祝福语
		map.put("client_ip", "127.0.0.1");//ip地址
		map.put("act_name", "爱尔眼科发红包啦");//活动名称
		map.put("remark", "音乐广播祝您生活愉快,万事如意！");//备注
		map.put("sign", MoneyUtils.createSign(map,partnerkey));//签名
		String result = "";
		try {
			System.out.println(MoneyUtils.createXML(map));
			result = MoneyUtils.doSendMoney(urlOne, MoneyUtils.createXML(map),mchId,keystoreFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("result:"+result);
		
		
		/*
		String opendId = "ocRCht30egQfAJb3sEvqZYNfA8-M";
		String appId = "wx3c8731013f97c162";
		String mchId = "1229736002";
		String partnerkey = "oukeduooukeduooukeduooukeduoouke";
		String keystoreFile = "D:/WeChatCert/certificate/oukeduo/apiclient_cert.p12";
		
		String orderNNo =  MoneyUtils.getOrderNo(mchId) ; 
		System.out.println(orderNNo);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("nonce_str", MoneyUtils.buildRandom());//随机字符串
		map.put("mch_billno", "123");//商户订单
		map.put("mch_id", mchId);//商户号
		map.put("wxappid", appId);//商户appid
		map.put("nick_name", "欧客哆休闲食品");//提供方名称
		map.put("send_name", "欧客哆休闲食品");//用户名
		map.put("re_openid", opendId);//用户openid
		map.put("total_amount", 100);//付款金额
		map.put("min_value", 100);//最小红包
		map.put("max_value", 100);//最大红包
		map.put("total_num", 1);//红包发送总人数
		map.put("wishing", "欧客哆商城祝您万事如意");//红包祝福语
		map.put("client_ip", "127.0.0.1");//ip地址
		map.put("act_name", "欧客哆商城红包");//活动名称
		map.put("remark", "欧客哆商城祝您生活愉快,万事如意！");//备注
		map.put("sign", MoneyUtils.createSign(map,partnerkey));//签名
		String result = "";
		try {
			System.out.println(MoneyUtils.createXML(map));
			result = MoneyUtils.doSendMoney(urlOne, MoneyUtils.createXML(map),mchId,keystoreFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("result:"+result);
		*/
	}

	
	//退款申请测试
	public static void applyRefund() {
		String appId = "wxbe3a3deb182983e0";
		String partnerkey = "qiantaichazhuangqiantaichazhuang";
		String keystoreFile = "D:/WeChatCert/certificate/qiantai/apiclient_cert.p12";
		String mchId = "1235752602";
		String orderNNo =  MoneyUtils.getOrderNo(mchId); 
		System.out.println(orderNNo);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("appid", appId);
		map.put("mch_id", mchId);
		
		map.put("nonce_str", MoneyUtils.buildRandom());
		map.put("out_trade_no", "10501820150810091657");
		map.put("out_refund_no",orderNNo);
		map.put("total_fee", "1");
		map.put("refund_fee", "1");
		map.put("op_user_id", "1235752602");
		
		map.put("sign", MoneyUtils.createSign(map,partnerkey));
		
		String result = "";
		try {
			System.out.println(MoneyUtils.createXML(map));
			result = MoneyUtils.doSendMoney(urlFive, MoneyUtils.createXML(map),mchId,keystoreFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("result:"+result);
	}
}
